package com.lyt.controller;


import com.lyt.bean.TestStatus;
import com.lyt.service.TestStatuService;
import com.lyt.vo.TestStatusVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;

/**
 * @Author: 张勇
 * @Date: 2023/05/11
 * @Info：
 */
@RestController
@CrossOrigin
public class TestStatusController {
    @Autowired
    public TestStatuService service;

    @RequestMapping("/testStatus/add")  //添加考试的学生
    public TestStatusVo addTestStuts(@Param("id")Integer stu_id,@Param("name") String name)throws Exception{
        Integer stuId = service.selStuByStuId(stu_id);
        TestStatusVo testStatusVo = new TestStatusVo();
        if(stuId != null){
             testStatusVo =  service.selSubmitPaperTime(stu_id);
            return testStatusVo;
        }else {
            TestStatusVo testStatusVo2 = new TestStatusVo(stu_id,name,System.currentTimeMillis(),0,0);
            System.out.println(testStatusVo2.toString());
            service.addTestStatus(testStatusVo2);
        }
        return testStatusVo;
    }

    @RequestMapping("/testStatus/updateCunNum")
    public void updateCunNum(@Param("id")Integer stu_id){

        Integer num = service.selStuCutNumByStuId(stu_id);
        if(num != null) service.updateCutNum(stu_id,num+1);
    }

    @RequestMapping("/testStatus/selStuHandPaper")
    public Integer selStuHandPaperByStuId(@Param("id")Integer stu_id){

       Integer num =  service.selStuHandPaperByStuId(stu_id);

       return num;
    }

    @RequestMapping("/testStatus/selSubmitPaperTime")
    public TestStatusVo selSubmitPaperTime(@Param("id")Integer stu_id){

        TestStatusVo testStatusVo =  service.selSubmitPaperTime(stu_id);

        return testStatusVo;
    }

    @RequestMapping("/testStatus/updateSubmitPaperTime")
    public void updateSubmitPaperTime(@Param("stu_id")Integer stu_id){
        System.out.println("你在哪2222------------"+stu_id);
        service.updateSubmitPaperTime(stu_id,System.currentTimeMillis());
    }

    @RequestMapping("/testStatus/updateHandPaper")
    public void updateHandPaper(@Param("stu_id")Integer stu_id){
        System.out.println("你在哪------------"+stu_id);
        service.updateHandPaper(stu_id,1);
    }
}
